{{- $tabs := .Store.Get "tabs" -}}
{{- if not $tabs -}}
  {{- errorf "No tabs found. Please add at least one tab to the tabs shortcode. See %s %s" .Name .Position -}}
{{- end -}}
{{- $lenTabs := len $tabs -}}
{{- $defaultTab := .Get "defaultTab" | default 0 -}}
{{- $type := .Get "type" | default "underline" -}}
{{- $placement := .Get "placement" | default "top" -}}
{{- $placementMap := slice "top" "bottom" "left" "right" -}}
{{- if ge $defaultTab $lenTabs -}}
  {{- warnf "The defaultTab value %v is out of range [0, %v]. See %s %s" $defaultTab (sub $lenTabs 1) .Name .Position -}}
  {{- $defaultTab = 0 -}}
{{- end -}}
{{- if not (in $placementMap $placement) -}}
  {{- warnf "The placement value %q is invalid. Supported values are: %v. See %s %s" $placement (delimit $placementMap ", ") .Name .Position -}}
  {{- $placement = "top" -}}
{{- end -}}

{{- /* Tabs Container */ -}}
<tab-container default-tab="{{ $defaultTab }}" placement="{{ $placement }}"{{ with $type }} type="{{ . }}"{{ end }}>
  {{- range $index, $tab := $tabs -}}
    {{- $title := $tab.title | default (printf "Untitled%v" $index) -}}
    {{- $id := $tab.id -}}
    <button class="tab-button" type="button" role="tab" id="tab-{{ $id }}" aria-selected="{{ eq $index $defaultTab }}">{{ $title | $.Page.RenderString }}</button>
  {{- end -}}
  {{- .Inner -}}
</tab-container>
{{- .Page.Store.Set "hasTabs" true -}}
{{- if eq hugo.Context.MarkupScope "home" -}}
  {{- site.Home.Store.Set "hasTabs" true -}}
{{- end -}}
